Skip to content

fix(webapp): prevent IEEE 754 precision loss on OTLP nanosecond conversions - #5035

Closed
PatelRavip1 wants to merge 1 commit into
triggerdotdev:mainfrom
PatelRavip1:fix/issue-3292
Closed

PatelRavip1 wants to merge 1 commit into
triggerdotdev:mainfrom
PatelRavip1:fix/issue-3292

Conversation

@PatelRavip1

Copy link
Copy Markdown

Fixes #3292

Root Cause

Converting epoch milliseconds to nanoseconds via BigInt(ms * 1_000_000) performs multiplication in IEEE 754 float representation before casting to BigInt. Because epoch ms * 1e6 is ~1.7e18 and exceeds Number.MAX_SAFE_INTEGER (~9e15), the lowest bits lose precision, creating +-256ns non-deterministic drift in span ordering and duration metrics.

Changes

  • apps/webapp/app/v3/eventRepository/common.server.ts: Cast new Date().getTime() and $endtime.getTime() to BigInt prior to multiplying by BigInt(1_000_000).
  • apps/webapp/app/v3/eventRepository/index.server.ts: Cast timestamp to BigInt prior to multiplication.
  • apps/webapp/app/v3/runEngineHandlers.server.ts: Cast retry event timestamp to BigInt prior to multiplication.
  • apps/webapp/app/v3/eventRepository/common.server.test.ts: Added unit tests verifying exact integer arithmetic and absence of float truncation.

…rsions

Fixes triggerdotdev#3292

Root Cause:
Converting epoch milliseconds to nanoseconds via `BigInt(ms * 1_000_000)` performs
multiplication in IEEE 754 float representation before casting to BigInt. Because
epoch ms * 1e6 is ~1.7e18 and exceeds Number.MAX_SAFE_INTEGER (~9e15), the lowest
bits lose precision, creating +-256ns non-deterministic drift in span ordering and
duration metrics.

Resolution:
Cast epoch ms to BigInt before multiplying by BigInt(1_000_000) across all webapp
event repository and run engine call sites.
@changeset-bot

changeset-bot Bot commented Oct 17, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 80a90fc

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

Copy link
Copy Markdown
Contributor

Hi @PatelRavip1, thanks for your interest in contributing!

This project requires that pull request authors are vouched, and you are not in the list of vouched users.

This PR will be closed automatically. See https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md for more details.

@github-actions github-actions Bot closed this Oct 17, 2026
@coderabbitai

coderabbitai Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b6af14ed-8b8f-46e0-bd42-898396279f75
📥 Commits

Reviewing files that changed from the base of the PR and between 9f8cc32 and 80a90fc.

📒 Files selected for processing: 4
  • apps/webapp/app/v3/eventRepository/common.server.test.ts
  • apps/webapp/app/v3/eventRepository/common.server.ts
  • apps/webapp/app/v3/eventRepository/index.server.ts
  • apps/webapp/app/v3/runEngineHandlers.server.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 potential issues.

Devin Review


export function getNowInNanoseconds(): bigint {
return BigInt(new Date().getTime() * 1_000_000);
return BigInt(new Date().getTime()) * BigInt(1_000_000);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Span precision fix absent from release notes

When this fix changes recorded span times, getNowInNanoseconds gains no server change note. Customers miss the fix in release notes.

Learn more

A server change note is the user-facing release entry for a server-only fix. This PR changes the nanosecond timestamp used for recorded spans and their durations, but adds no entry under .server-changes/. The repository requires a note when a server-only bug fix affects behavior users could encounter; these files feed release notes for customers. See the server change rules.

Example: A customer sees span ordering drift before the upgrade and accurate ordering afterward, but the release notes omit the correction.

Recommended fix: Add a .server-changes/ Markdown file with area: webapp, type: fix, and a single user-facing sentence about more accurate span timing.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +19 to +23
it("preserves exact duration calculation", () => {
const start = 1729200000000n * 1_000_000n;
const end = new Date(1729200000500); // 500ms later
const duration = calculateDurationFromStart(end, start);
expect(duration).toBe(500_000_000);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Precision tests are absent from the default suite

The Vitest include list excludes this test directory. Its duration test also reverses calculateDurationFromStart arguments, so including it alone will not validate the fix.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OTLP nanosecond timestamp overflow in webapp event repository

1 participant